/*
wgetopt is released under the new bsd 3 clause license below:

Copyright (c) <2013>, <wilson birney>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the <wpbirney@gmail.com> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef wgetop_H
#define wgetop_H

//has_arg
#define no_arg  0
#define req_arg 1
#define opt_arg 2

//opt_type
#define opt_flag    0 //flag options begin with '-' and are a single char
#define opt_long    1 //long options begin with '--' and contain a cstring
#define opt_pos     2 //pos options are based on arg index in argv[i]
#define opt_any     3 //any options are any arg in argv without a leading '-' or "--"

#include <iostream>
#include <cstring>
#include <cstdlib>
struct wpinfo
{
    char* name;
    char* desc;
    char* vers;
};
struct wopt {
    wopt();
    wopt(char* name_, int opt_type_, int has_arg_, bool* opt_, void (*func_)());
    char *name;
    char *optarg;
    int has_arg;
    int opt_type;
    int index;
    bool* opt;
    char* desc;
    void (*func)();
};
struct wgetopt {
    wgetopt();
    wgetopt(int maxsz);
    ~wgetopt();
    char **unopts;
    int unopts_sz;
    int sz;
    wopt *opts;
    wpinfo *info;
    int addopt(char* name, int opt_type, int has_arg, bool* opt, void (*func)());
    int addindexarg(int index, void (*func)());
    int addflagopt(char* flag, bool* bptr);
    void setlastdesc(char* des);
    void toggleopt(wopt* w);
    void checkarg(char** argv, int *i, int *r);
    void parse(int argc, char** argv);
};

void printusage(wgetopt *o);


#endif // wgetop_H

